#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    string lowestMaleName,lowestMaleId;
    int lowestMaleGrade=101;
    string highestFemaleName,highestFemaleId;
    int highestFemaleGrade=-1;
    while(n-->0){
        string name,id;
        char gender;
        int grade;
        cin>>name>>gender>>id>>grade;
        if(gender=='M'){
            if(lowestMaleGrade>grade){
                lowestMaleName=name;
                lowestMaleId=id;
                lowestMaleGrade=grade;
            }
        }else{
            if(highestFemaleGrade<grade){
                highestFemaleGrade=grade;
                highestFemaleId=id;
                highestFemaleName=name;
            }
        }
    }
    int flag=true;
    if(highestFemaleGrade<0){
        cout<<"Absent"<<endl;
        flag=false;
    }else{
        cout<<highestFemaleName<<" "<<highestFemaleId<<endl;
    }
    if(lowestMaleGrade>100){
        cout<<"Absent"<<endl;
        flag=false;
    }else{
        cout<<lowestMaleName<<" "<<lowestMaleId<<endl;
    }
    if(!flag){
        cout<<"NA"<<endl;
    }else{
        int gradef_gradem=highestFemaleGrade-lowestMaleGrade;
        cout<<gradef_gradem<<endl;
    }
    return 0;
}
